//---------------------------------------------------------------------
// <copyright file="EFOracleConnection.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//---------------------------------------------------------------------

namespace EFOracleOdpProvider
{
    using System;
    using System.Data;
    using System.Data.Common;
    using Oracle.DataAccess;
    using Oracle.DataAccess.Client;

    

    /// <summary>
    /// Wrapper for OracleConnection adding DbProviderFactory property introduced in ADO.NET 3.
    /// </summary>
    public partial class EFOracleOdpConnection : DbConnection, ICloneable
    {
        #region Private Fields

        private OracleConnection _oracleConnection = new OracleConnection();

        #endregion 

        #region Constructors

        public EFOracleOdpConnection()
        {
        }

        public EFOracleOdpConnection(string connectionString)
        {
            this.ConnectionString = connectionString;
        }

        #endregion

        #region Properties

        protected override DbProviderFactory DbProviderFactory
        {
            get { return EFOracleOdpProviderFactory.Instance; }
        }

        public override string ServerVersion
        {
            get { return this._oracleConnection.ServerVersion; }
        }

        public override ConnectionState State
        {
            get { return this._oracleConnection.State; }
        }

        public override string ConnectionString
        {
            get { return this._oracleConnection.ConnectionString; }
            set { this._oracleConnection.ConnectionString = value; }
        }

        public override int ConnectionTimeout
        {
            get { return this._oracleConnection.ConnectionTimeout; }
        }

        public override string Database
        {
            get { return this._oracleConnection.Database; }
        }

        public override string DataSource
        {
            get { return this._oracleConnection.DataSource; }
        }

        public override System.ComponentModel.ISite Site
        {
            get { return this._oracleConnection.Site; }
            set { this._oracleConnection.Site = value; }
        }

        internal OracleConnection OracleConnection
        {
            get { return _oracleConnection; }
        }

        #endregion

        #region Methods

        protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
        {
            return this._oracleConnection.BeginTransaction(isolationLevel);
        }

        public override void ChangeDatabase(string databaseName)
        {
            this._oracleConnection.ChangeDatabase(databaseName);
        }

        public override void Close()
        { 
            this._oracleConnection.Close();
        }

        protected override DbCommand CreateDbCommand()
        {
            DbCommand command = EFOracleOdpProviderFactory.Instance.CreateCommand();
            command.Connection = this;
            return command;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                this._oracleConnection.Dispose();
            }
            base.Dispose(disposing);
        }

        public override void EnlistTransaction(System.Transactions.Transaction transaction)
        {
            this._oracleConnection.EnlistTransaction(transaction);
        }

        public override DataTable GetSchema(string collectionName)
        {
            return this._oracleConnection.GetSchema(collectionName);
        }

        public override DataTable GetSchema()
        {
            return this._oracleConnection.GetSchema();
        }

        public override DataTable GetSchema(string collectionName, string[] restrictionValues)
        {
            return this._oracleConnection.GetSchema(collectionName, restrictionValues);
        }

        public override void Open()
        {
            this._oracleConnection.Open();
        }

        #endregion

        #region ICloneable

        object ICloneable.Clone()
        {
            EFOracleOdpConnection clone = new EFOracleOdpConnection();
            clone._oracleConnection = (OracleConnection) ((ICloneable) this._oracleConnection).Clone();
            return clone;
        }

        #endregion
    }
}
